﻿// ## 2024/1/20 # 铃 # 由于263,264函数似乎存在无法理解的BUG,因此主动使用 ##



namespace AI优化_增强出征指令
{
    const int 据点主动进攻_战斗部队数 = 15;
    const int 据点主动进攻_攻城部队数 = 5;

    //------------------------------------------------------------

//=======================================================================================

    class Main
    {
        pk::c_bool 调试模式 = pk::c_bool(false);
        pk::c_bool 调试模式2 = pk::c_bool(false);
        pk::force @force_t;
        pk::list<pk::person @> except_person_list;


        Main()
        {
            pk::bind(202, pk::trigger202_t(onAIRunningOrder));
            pk::bind(260, pk::trigger260_t(增强出征_725_打印));
        }

        //---------------------------------------------------------------------------------------
        //          据点进攻执行函数
        //---------------------------------------------------------------------------------------

        pk::list<pk::building @> list_target_base; // 需要攻击的交战据点列表
        pk::list<pk::building @> list_attack_base; // 攻击部队出征据点列表
        int siege_count = 0;
        int unit_count = 0;


        void 增强出征_725_打印()
        {
            ImGui::Checkbox("简略信息", 调试模式);
            ImGui::Checkbox("详细信息", 调试模式2);

        }

        void onAIRunningOrder(pk::ai_context @context, pk::building @base, int cmd)
        {
            if (cmd == 据点AI_增强出征)
            {
                int base_id = base.get_id();
                pk::force@ force = context.force;
                @force_t = context.force;
                // pk::trace(pk::format("增强进攻,遍历据点{},({}军)),打印开关{}", pk::decode(pk::get_name(base)), pk::decode(pk::get_name(force)),调试模式.v));
                int max_energy = ch::get_max_energy(false);

                if (调试模式.v) pk::trace(pk::format("前置判断,({}军))", pk::decode(pk::get_name(force))));

                if (pk::get_elapsed_months() > 6 and pk::get_troops(base) > 30000 and base.energy >= max_energy and pk::get_food(base) > 90000)
                {
                    pk::building @dst_base = AI_ATTACK_CITY_WEIGHT::main.calc_weight(base);
                    if (dst_base is null) return;

                    if (pk::is_enemy(dst_base, base) or dst_base.get_force_id() == -1)
                    {
                        if (调试模式.v) pk::trace(pk::format("主动进攻,对{}的据点发送攻击指令.({}军))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(force))));
                        push_attack(base, dst_base, force);

                    }
                }
            }
        }
        //---------------------------------------------------------------------------------------
        // 指定发送到攻击目标的部队类型
        bool push_attack(pk::building @src_base, pk::building @dst_base, pk::force @force)
        {
            auto person_list = pk::get_idle_person_list(src_base);
            if (person_list.count == 0)
                return false; // 武将不足


            // 根据敌方兵力数,计算留存量,可用兵力小于留存量则不支援.
            int ref_troops = ai::retained_troops[src_base.get_id()];

            if (pk::get_troops(src_base) < ref_troops)
                return false; // 兵力不足

            int src_troops = pk::get_troops(src_base);
            int src_food = pk::get_food(src_base);

            if (src_food < int(2.0f * ref_troops))
                return false;

            int building_id = pk::get_building_id(dst_base.pos);

            // 攻击战力是包括所有直所有攻击目标的战力,防守战力只能限于城市区域内的战力
            int atk_power = ai::force_attack_base_troops[force.get_id()][dst_base.get_id()];
            int def_power = ai::base_around_self_troops[dst_base.get_id()] + ch::city_spec_troops(dst_base) / 2 + pk::get_troops(dst_base);

            int status = atk_power - def_power;
            string status_info = "";

            bool cmd = false;

            cmd = (push_attack_order(dst_base, src_base, 部队类型_战斗, /*siege_weapon*/ false, /*max_unit*/ 15) or cmd); // 战斗部队

            if (调试模式.v)
            {
                pk::force @def_force = pk::get_force(dst_base.get_force_id());
                pk::force @atk_force = force;
                string dst_name = pk::decode(pk::get_name(dst_base));
                string src_name = pk::decode(pk::get_name(src_base));
                string def_force_name;
                string atk_force_name;
                if (def_force !is null)
                {
                    def_force_name = pk::decode(pk::get_name(pk::get_person(def_force.kunshu)));
                    atk_force_name = pk::decode(pk::get_name(pk::get_person(atk_force.kunshu)));
                }

                if (cmd)
                    pk::trace(pk::format("主动进攻:{}军从{}出征→{}军{}", atk_force_name, src_name, def_force_name, dst_name));
            }
            return true;
        }


        //---------------------------------------------------------------------------------------
        bool push_attack_order(pk::building @dst_base, pk::building @src_base, int attack_type, bool siege_weapon = false, int max_unit = 1)
        {
            // 进攻出发据点
            int src_id = src_base.get_id();
            int dst_id = dst_base.get_id();

            // 出击命令条件
            siege_count = 0;
            unit_count = 0;
            int push_count = 0;
            int 已出征兵力 = ai::force_attack_base_troops[force_t.get_id()][dst_base.get_id()];
            int 据点范围己方兵力 = ai::base_around_self_troops[dst_base.get_id()];
            int 玩家修正 = (dst_base.is_player() ? 200000 : 0);
            if (pk::get_scenario().difficulty == 难易度_初级) 玩家修正 = 0;
            if (pk::get_scenario().difficulty == 难易度_上级) 玩家修正 = 10 * 10000;
            if (pk::get_scenario().difficulty == 难易度_超级) 玩家修正 = 15 * 10000;
            int 最大兵力 = 10 * 10000 + 据点范围己方兵力 * 2 + pk::get_troops(dst_base) + ch::city_spec_troops(dst_base) + 玩家修正;
            if (dst_base.get_id() >= 城市_末) 最大兵力 /= 2;
            if (dst_base.get_force_id() == -1) pk::min(最大兵力, 50000);

            if (调试模式2.v)  pk::trace(pk::format("7对{}的进攻,从{}出发,已出征兵力{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)), 已出征兵力));

            // 在出发据点上循环执行出击命令
            //最大兵力不超过野战部队+据点兵+封地兵+10万
            int person_count = pk::get_idle_person_list(src_base).count;
            for (int i = 0; i < person_count; i++)
            {
                if (调试模式2.v)  pk::trace(pk::format("7.5对{}的进攻,从{}出发,i{},人数{},已出征兵力{},最大兵力{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)),i,pk::get_idle_person_list(src_base).count,已出征兵力,最大兵力));

                if (已出征兵力 < 最大兵力 and pk::get_troops(src_base) > 10000 )
                {
                    push_count += 1;
                    if (调试模式2.v)  pk::trace(pk::format("8对{}的进攻,从{}出发))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base))));
                    int unit_id = push_battle_unit(src_base, dst_base, true, 0 /*type 0为进攻,1为防御*/);
                    if (unit_id != -1)
                    {
                        unit_count += 1;
                        if (is_siege_weapon(pk::get_unit(unit_id).weapon))
                            siege_count += 1; // 战斗部队计数


                        if (!list_attack_base.contains(src_base))
                            list_attack_base.add(src_base);
                    }
                }
            }

            if (unit_count > 0)
                return true;

            return false;
        }



    //*******************************************  野战部队出征 ****************************************************************
        int push_battle_unit(pk::building @src_base, pk::building @dst_base, bool do_cmd = true, int type = 0)
        {

            if (调试模式2.v)  pk::trace(pk::format("11对{}的进攻,从{}出发))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base))));

            if (!pk::is_alive(src_base) or !pk::is_alive(dst_base) or pk::is_player_controlled(src_base))
                return -1;

            int ref_troops = ai::retained_troops[src_base.get_id()];


            if (调试模式2.v)  pk::trace(pk::format("12对{}的进攻,从{}出发,留存{},现有{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)), ref_troops, pk::get_troops(src_base)));

            if (pk::get_troops(src_base) < ref_troops - 5000)
                return -1; // 兵力不足

            auto person_list = pk::get_idle_person_list(src_base);
            if (person_list.count == 0)
                return -1; // 武将不足

            if (调试模式2.v)  pk::trace(pk::format("13对{}的进攻,从{}出发,留存{},现有{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)), ref_troops, pk::get_troops(src_base)));

            //********************  武将能力打分  **********************
            person_list.sort(function(a, b) {
                int a_score = a.stat[武将能力_武力] * UNIT_ATTR::攻武占比 + a.stat[武将能力_统率] * UNIT_ATTR::攻统占比 * 2 + a.stat[武将能力_智力] * UNIT_ATTR::防智占比;
                int b_score = b.stat[武将能力_武力] * UNIT_ATTR::攻武占比 + b.stat[武将能力_统率] * UNIT_ATTR::攻统占比 * 2 + b.stat[武将能力_智力] * UNIT_ATTR::防智占比;
                // 考虑武将能力
                return (a_score > b_score);
            });

            int person_id = -1;

            for (int i = 0; i < person_list.count; i++)
            {
                if (person_list[i].stat[武将能力_统率] + person_list[i].stat[武将能力_武力] / 2 + person_list[i].stat[武将能力_智力] / 2 < 80)
                    continue;

                //弱势君主不出征
                if (pk::get_kunshu_id(person_list[i]) == person_list[i].get_id() and person_list[i].stat[武将能力_统率] + person_list[i].stat[武将能力_武力] / 2 + person_list[i].stat[武将能力_智力] / 2 < 120)
                    continue;

                if (except_person_list.contains(person_list[i]))
                    continue;

                person_id = person_list[i].get_id();
                if (person_id >= 0) break;
            }

            if (person_id == -1) return -1;
            pk::person @leader = pk::get_person(person_id);

            if (调试模式2.v)  pk::trace(pk::format("14对{}的进攻,从{}出发,留存{},现有{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)), ref_troops, pk::get_troops(src_base)));

            // 计算出发部队兵力：超过基准兵力，确认指挥能力
            int reinforce_troops = pk::min(20000, pk::get_command(leader), pk::max(5000, pk::get_troops(src_base) - ref_troops));

            // 选择最佳的武器
            int ground_weapon_id = 兵器_剑;
            int ground_weapon_score = 0;

            int unit_troops = reinforce_troops;

            //*******************  陆地兵器  ******************
            // 选择陆上武器
            ground_weapon_id = get_ground_weapon(src_base, leader, dst_base, type).first;
            ground_weapon_score = get_ground_weapon(src_base, leader, dst_base, type).second;

            //pk::trace(pk::decode(pk::get_name(leader)) + get_weapon_name(ground_weapon_id) + "ground_weapon_id" + ground_weapon_id + "ground_weapon_score:" + ground_weapon_score + ",unit_troops :" + unit_troops);

            if (ground_weapon_score == 0 or ground_weapon_id == 0)
            {
                except_person_list.add(leader);
                return -1; // 兵器不足
            }

            if (调试模式2.v)  pk::trace(pk::format("15对{}的进攻,从{}出发,留存{},现有{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)), ref_troops, pk::get_troops(src_base)));

            if (ground_weapon_id <= 兵器_战马)
            {
                unit_troops = pk::min(unit_troops, pk::get_weapon_amount(src_base, ground_weapon_id));
                if (unit_troops < 5000) return -1;
            }

            if (调试模式2.v)  pk::trace(pk::format("16对{}的进攻,从{}出发,留存{},现有{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)), ref_troops, pk::get_troops(src_base)));

            //********************  水上兵器  ***********************
            // 选择水上武器
            // if (building_sea_enemy_count(src_base) > 0 and building_sea_enemy_count(dst_base) > 0)
            // {
            //     if (leader.tekisei[兵种_水军] == 适性_C)
            //         water_weapon_id = 兵器_走舸;
            //     else
            //     {
            //         if (pk::get_weapon_amount(src_base, 兵器_楼船) > 0)
            //             water_weapon_id = 兵器_楼船;
            //         else if (pk::get_weapon_amount(src_base, 兵器_斗舰) > 0)
            //             water_weapon_id = 兵器_斗舰;
            //         else
            //             water_weapon_id = 兵器_走舸;
            //     }
            // }
            // else
            //     water_weapon_id = 兵器_走舸;
            int water_weapon_id = 兵器_走舸;
            int water_weapon = 兵器_楼船;
            if (pk::has_tech(src_base, 技巧_开发投石))
                water_weapon = 兵器_斗舰;

               //必须经过水域的时候,有船就用船.不管是谁
            if (must_water_count[src_base.get_id()][dst_base.get_id()] >= 2)
            {
                if (pk::get_weapon_amount(src_base, water_weapon) > 0)
                    water_weapon_id = water_weapon;
            }

            else if (option_water_count[src_base.get_id()][dst_base.get_id()] >= 2)
            {
                //充足的时候随便用
                if (pk::get_weapon_amount(src_base, water_weapon) >= 8)
                    water_weapon_id = water_weapon;
                                //充足的时候随便用
                else
                {
                    if (leader.tekisei[兵种_水军] == 适性_C)
                        water_weapon_id = 兵器_走舸;
                    else  water_weapon_id = water_weapon;
                }

            }

         //**********************  新粮草计算  **********************
         // 使用新的unit_distance计算部队消耗
         // 最终带粮基准值为路上*2+12回合战斗
            int base_weight = unit_distance[src_base.get_id()][dst_base.get_id()];

            if (pk::get_food(src_base) > pk::get_troops(src_base) * 5 and pk::get_food(src_base) > 120000)
                base_weight += 1;

            float rate = (base_weight * 2 + 12);
            // if ((ground_weapon_id > 兵器_战马 and ground_weapon_id < 兵器_走舸) or ground_weapon_id == 兵器_戟) // 跑得慢的多加一些
            //     rate *= 1.25f;

            rate = pk::min(rate, 35.0); // 无论如何都不会超过350天,防止带的太多影响城市粮草
            int unit_food = int(unit_troops * rate / 10);

            if (调试模式2.v)  pk::trace(pk::format("17对{}的进攻,从{}出发,带粮{},城市现有粮{},城市剩余兵{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)), unit_food, pk::get_food(src_base), pk::get_troops(src_base) - unit_troops));

            if (int(pk::get_food(src_base) - int(unit_food)) < int(pk::get_troops(src_base)))
            {
                int 最大可带粮 = pk::max(0, int(pk::get_food(src_base)) - int(pk::get_troops(src_base) * 0.3));
                int 最大兵力 = 最大可带粮 / 2;
                unit_troops = pk::min(最大兵力, unit_troops);
                if (unit_troops < 5000) return -1;
            }

            if (int(pk::get_troops(src_base)) - unit_troops < 5000)
                return -1;

            if (unit_troops < 5000)
                return -1;

            if (调试模式2.v)  pk::trace(pk::format("18对{}的进攻,从{}出发,留存{},现有{}))", pk::decode(pk::get_name(dst_base)), pk::decode(pk::get_name(src_base)), ref_troops, pk::get_troops(src_base)));

            //*************************** 野战部队出征指令  ********************
            if (do_cmd)
            {
                // 出征命令信息生成
                pk::com_march_cmd_info cmd;
                @cmd.base = @src_base;
                cmd.type = 部队类型_战斗;
                cmd.member[0] = leader.get_id();
                cmd.gold = (pk::get_gold(src_base) >= 5000) ? int(pk::min(1200, pk::max(500, pk::get_gold(src_base) / 10))) : 0;
                cmd.troops = pk::max(5000, unit_troops);
                cmd.weapon_id[0] = ground_weapon_id;
                cmd.weapon_id[1] = water_weapon_id;
                cmd.weapon_amount[0] = (is_siege_weapon(ground_weapon_id)) ? 1 : pk::max(1, unit_troops);
                cmd.weapon_amount[1] = (water_weapon_id == 兵器_走舸) ? 0 : 1;
                cmd.food = pk::min(50000, unit_food);


                cmd.order = (pk::is_enemy(src_base, dst_base) ? 部队任务_征服 : 部队任务_移动);

                if (dst_base.get_force_id() == -1) cmd.order = 部队任务_攻击;

                cmd.target_pos = dst_base.get_pos(); // 目标是战斗中的据点

                //ai出征优化::main.march_modify(cmd,1/*0防御，1攻击，2建设，3运输*/);//实际上前方只用给出大概的主将和目标就行了，剩下的全部可以走优化

                leader.action_done = true;
                int unit_id = pk::command(cmd);

                pk::unit @unit_cmd = pk::get_unit(unit_id);
                if (pk::is_alive(unit_cmd))
                {
                    unit_cmd.action_done = true;
                    if (type == 0) ai::force_attack_base_troops[force_t.get_id()][dst_base.get_id()] += unit_cmd.troops;

                    if (调试模式.v)
                    {
                        string src_name = pk::decode(pk::get_name(src_base));
                        string dst_name = pk::decode(pk::get_name(dst_base));
                        string unit_name = pk::decode(pk::get_name(leader));
                        string order_str = get_order_info(unit_cmd.order);
                        string cmd_info;
                        cmd_info = "主动进攻";
                        pk::trace(pk::format("{}: {}队从 {}出征:→ {}", cmd_info, unit_name, src_name, dst_name));

                    }
                    return unit_id;
                }
            }

            return -1;
        }

        //******************************************* 武器选择函数   ****************************************************************
        pk::int_int get_ground_weapon(pk::building @base, pk::person @leader, pk::building @dst_base, int type)
        {
            array<int> heishu_score(兵器_末, 0);    // 适性评分，是否可以参考副将补全
            array<bool> can_march(兵器_末, false);  // 是否有足够兵器可出征
            array<int> tech_score(兵器_末, 0);      // 已研究科技评分
            array<int> ling_score(兵器_末, 0);      // 根据态势调整
            array<int> skill_score(兵器_末, 0); // 总特技评分
            array<int> all_score(兵器_末, 0);       // 兵器和适性的总评分

            int siege_max = 1;
            if (pk::get_troops(base) > 50000)  siege_max = 2;
            if (pk::get_troops(base) >= 100000)  siege_max = 3;
            siege_max += pk::max((int(pk::get_troops(base) / 5000) + unit_count) / 5 - 1, 0);   //模拟预估计算总部队数


            //AI用不好骑兵.尽量给其他兵种
            ling_score[兵器_战马] -= 3;
            ling_score[兵器_枪] += 1;
            ling_score[兵器_弩] += 1;
            ling_score[兵器_戟] += 1;
            ling_score[兵器_冲车] += 3;
            ling_score[兵器_木兽] += 3;
            ling_score[兵器_投石] += 5;

            if (pk::get_kunshu_id(leader) == leader.get_id())
            {
                ling_score[兵器_战马] -= 5;
                ling_score[兵器_枪] -= 3;
                ling_score[兵器_弩] += 1;
                ling_score[兵器_戟] += 1;
                ling_score[兵器_冲车] -= 3;
                ling_score[兵器_木兽] -= 3;
                ling_score[兵器_投石] += 5;
            }

            if (ch::is_gate(dst_base.get_id())) //对关隘进行攻城
            {
                ling_score[兵器_战马] -= 3;
                ling_score[兵器_冲车] += 3;
                ling_score[兵器_木兽] += 5;
                ling_score[兵器_井阑] += 5;
                ling_score[兵器_投石] += 6;
                siege_max += 2;

            }

            int dst_province_id = pk::get_province_id(dst_base.pos);

            if (dst_province_id == 州_益州)
            {
                ling_score[兵器_枪] += 3;
                ling_score[兵器_战马] -= 3;
            }

            if (dst_province_id == 州_幽州 or dst_province_id == 州_凉州)
            {
                ling_score[兵器_弩] -= 3;
                ling_score[兵器_戟] -= 3;
                ling_score[兵器_战马] += 5;
                ling_score[兵器_枪] += 3;
            }

            //特殊城市继续强化
            if (dst_base.get_id() == 铃据点_云南 or dst_base.get_id() == 铃据点_建宁 or dst_base.get_id() == 铃据点_汝南)
            {
                ling_score[兵器_弩] -= 3;
                ling_score[兵器_战马] -= 10;
                ling_score[兵器_枪] += 3;
                ling_score[兵器_戟] += 1;
            }



            pk::force @force0 = pk::get_force(leader.get_force_id());
            for (int i = 0; i < 兵器_走舸; i++)
            {

                //pk::trace(pk::decode(pk::get_name(leader)) + get_weapon_name(i) + "1科技分:" + tech_score[i] + "特技分:" + skill_score[i] + ",适性分:" + heishu_score[i] * 3 + ",态势分:" + ling_score[i] + ",总分:" + all_score[i] + "适性" + leader.tekisei[pk::equipment_id_to_heishu(i)]);

                if (leader.tekisei[pk::equipment_id_to_heishu(i)] < 适性_B)
                {
                    can_march[i] = false;
                    //pk::trace(pk::decode(pk::get_name(leader)) + get_weapon_name(i) + "2科技分:" + tech_score[i] + "特技分:" + skill_score[i] + ",适性分:" + heishu_score[i] * 3 + ",态势分:" + ling_score[i] + ",总分:" + all_score[i] + "适性" + leader.tekisei[pk::equipment_id_to_heishu(i)]);

                }


                else if ((i == 兵器_冲车 or i == 兵器_木兽 or i == 兵器_井阑 or i == 兵器_投石) and leader.tekisei[pk::equipment_id_to_heishu(i)] < (ch::is_gate(dst_base.get_id()) ? 适性_A : 适性_A))//野战部队除非有S兵器,否则不出兵器
                {
                    can_march[i] = false;
                    //pk::trace(pk::decode(pk::get_name(leader)) + get_weapon_name(i) + "3科技分:" + tech_score[i] + "特技分:" + skill_score[i] + ",适性分:" + heishu_score[i] * 3 + ",态势分:" + ling_score[i] + ",总分:" + all_score[i] + "适性" + leader.tekisei[pk::equipment_id_to_heishu(i)]);

                }

                else if ((i == 兵器_冲车 or i == 兵器_木兽 or i == 兵器_井阑 or i == 兵器_投石) and siege_count >= siege_max)//兵器数量不大于3
                {
                    can_march[i] = false;
                    //pk::trace(pk::decode(pk::get_name(leader)) + get_weapon_name(i) + "4科技分:" + tech_score[i] + "特技分:" + skill_score[i] + ",适性分:" + heishu_score[i] * 3 + ",态势分:" + ling_score[i] + ",总分:" + all_score[i] + "适性" + leader.tekisei[pk::equipment_id_to_heishu(i)] + "siege_count"+siege_count);

                }

                else if (ch::check_weapon_able(base, i))
                {
                    can_march[i] = true;
                    //pk::trace(pk::decode(pk::get_name(leader)) + get_weapon_name(i) + "5科技分:" + tech_score[i] + "特技分:" + skill_score[i] + ",适性分:" + heishu_score[i] * 3 + ",态势分:" + ling_score[i] + ",总分:" + all_score[i] + "适性" + leader.tekisei[pk::equipment_id_to_heishu(i)]);

                }

                if (can_march[i])
                {
                    if (i == 兵器_剑)  heishu_score[i] = 0;
                    else heishu_score[i] = leader.tekisei[pk::equipment_id_to_heishu(i)];
                    tech_score[i] = ch::get_tech_score(force0, i);

                    int skill_id = leader.skill;
                    if (skill_id < 211 and skill_id >-1)
                    {
                    //pk::trace(pk::decode(pk::get_name(leader)) + get_weapon_name(i) + "i:" +i + "skill_id :" +skill_id );
                        skill_score[i] = ai出征优化::skill_score[skill_id][i];
                    }
                    all_score[i] = heishu_score[i] * 3 + tech_score[i] + skill_score[i] + ling_score[i];

                    //pk::trace(pk::decode(pk::get_name(leader)) + get_weapon_name(i) + "科技分:" + tech_score[i] + "特技分:" + skill_score[i] + ",适性分:" + heishu_score[i] * 3 + ",态势分:" + ling_score[i] + ",总分:" + all_score[i]);

                }
            }

            return pk::int_int(get_arr_max(all_score));
        }

        pk::int_int get_arr_max(array<int> score)
        {
            int best_score = 0;
            int id = 0;
            for (int i = 0; i < int(score.length); i++)
            {
                if (score[i] > best_score)
                {
                    best_score = score[i];
                    id = i;
                }
            }

            return pk::int_int(id, best_score);
        }


        //******************************************* 攻城工具判断   ****************************************************************
        bool is_siege_weapon(int weapon_id)
        {
            if (兵器_冲车 <= weapon_id and weapon_id <= 兵器_木兽)
                return true;
            return false;
        }

        //******************************************* 水上武器判断   ****************************************************************
        int building_sea_enemy_count(pk::building @building)
        {
            // 计算海上敌对势力
            int route_type = -1;
            int sea_enemy_count = 0;
            for (int i = 0; i < 6; i++)
            {
                int neighbor_base_id = pk::get_neighbor_area_building(building.get_id(), i);
                if (neighbor_base_id >= 0 and neighbor_base_id <= 据点_末)
                {
                    route_type = pk::get_neighbor_area_route(building.get_id(), i);

                    if (pk::is_enemy(building, pk::get_building(neighbor_base_id)) and route_type == 路径_海洋)
                        sea_enemy_count++;
                }
            }
            return sea_enemy_count;
        }

        //---------------------------------------------------------------------------------------
        string get_weapon_name(int weapon_id)
        {
            string weapon_name;
            switch (weapon_id)
            {
                case 兵器_剑:
                    weapon_name = "剑兵";
                    break;
                case 兵器_枪:
                    weapon_name = "枪兵";
                    break;
                case 兵器_戟:
                    weapon_name = "戟兵";
                    break;
                case 兵器_弩:
                    weapon_name = "弓兵";
                    break;
                case 兵器_战马:
                    weapon_name = "骑兵";
                    break;
                case 兵器_冲车:
                    weapon_name = "冲车";
                    break;
                case 兵器_井阑:
                    weapon_name = "井栏";
                    break;
                case 兵器_投石:
                    weapon_name = "投石";
                    break;
                case 兵器_木兽:
                    weapon_name = "木兽";
                    break;
                case 兵器_走舸:
                    weapon_name = "走舸";
                    break;
                case 兵器_楼船:
                    weapon_name = "楼船";
                    break;
                case 兵器_斗舰:
                    weapon_name = "斗舰";
                    break;
                default:
                    weapon_name = "??";
                    break;
            }
            return weapon_name;
        }

        string get_order_info(int order)
        {
            string name;
            switch (order)
            {
                case 0:
                    name = "部队任务_待命";
                    break;
                case 1:
                    name = "部队任务_移动";
                    break;
                case 2:
                    name = "部队任务_设置";
                    break;
                case 3:
                    name = "部队任务_征服";
                    break;
                case 4:
                    name = "部队任务_撤退";
                    break;
                case 5:
                    name = "部队任务_拦截";
                    break;
                case 6:
                    name = "部队任务_护卫";
                    break;
                case 7:
                    name = "部队任务_攻城";
                    break;
                case 8:
                    name = "部队任务_修复";
                    break;
                case 9:
                    name = "部队任务_征服";
                    break;
                case 10:
                    name = "部队任务_补给";
                    break;
                case 11:
                    name = "部队任务_歼灭";
                    break;
                case 12:
                    name = "部队任务_追随";
                    break;
                case 13:
                    name = "部队任务_末";
                    break;
                default:
                    name = "部队任务_没有";
                    break;
            }

            return name;
        }

        //---------------------------------------------------------------------------------------
    };

    Main main;
}